import React from 'react';
import New from './New';
import { withRouter } from 'react-router-dom';
import { observer, inject } from 'mobx-react';
import { searchToQuery } from '../../util';

/**
 * 支持从地址栏传入参数的List,只在第一层路由使用
 */
@inject('newStore')
@withRouter
@observer
export default class NewByLocation extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      params: {}
    };
  }
  componentDidMount() {
    this.setParamByLocation(this.props.location.search)
  }
  
  /*强绑定下内部邮件浏览框会出问题，这里去掉。
  componentWillReceiveProps(nextProps) {
    if (nextProps.location.search !== this.props.location.search) {
      this.setParamByLocation(nextProps.location.search);
    }
  }*/
  
  setParamByLocation = (search) => {
    this.setState({params: searchToQuery(search)});
  }
  render() {
    return (
      <New path='/new' params={this.state.params}/>
    );
  }
}